home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Graphics / Gallery / Source / ManagerWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  11.3 KB  |  452 lines

  1. #include <stream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <clib/utility_protos.h>
  9.  
  10. #include "GUIC_Application.hpp"
  11. #include "GUIC_Button.hpp"
  12. #include "GUIC_Date.hpp"
  13. #include "GUIC_DirectoryExamine.hpp"
  14. #include "GUIC_Error.hpp"
  15. #include "GUIC_Event.hpp"
  16. #include "GUIC_Exceptions.hpp"
  17. #include "GUIC_File.hpp"
  18. #include "GUIC_FileExamine.hpp"
  19. #include "GUIC_GGFXPicture.hpp"
  20. #include "GUIC_ImageButton.hpp"
  21. #include "GUIC_Label.hpp"
  22. #include "GUIC_Message.hpp"
  23. #include "GUIC_Panel.hpp"
  24. #include "GUIC_PathString.hpp"
  25. #include "GUIC_Prop.hpp"
  26. #include "GUIC_Screen.hpp"
  27. #include "GUIC_Separator.hpp"
  28. #include "GUIC_SlideButton.hpp"
  29. #include "GUIC_StringType.hpp"
  30. #include "GUIC_System.hpp"
  31. #include "GUIC_Textfield.hpp"
  32.  
  33. #include "ManagerWindow.hpp"
  34. #include "PrefsWindow.hpp"
  35.  
  36. #include "GUIC_PropWithArrows.hpp"
  37. GUIC_PropWithArrowsC *prop;
  38.  
  39. /*********************************************************************************************************/
  40.  
  41. class ManagerWindowC_ListEntry : public GUIC_ObjectC
  42.     {
  43.     public:
  44.         ManagerWindowC_ListEntry    (GUIC_FileExamineC *file, STRPTR temp, GUIC_TextfieldC *message);
  45.         ~ManagerWindowC_ListEntry    (VOID);
  46.         
  47.         STRPTR        getClass                (VOID);
  48.         VOID            print                    (VOID);
  49.         LONG            compare                (GUIC_ObjectC &o);
  50.         
  51.         STRPTR         fileName, dimensions, thumbnailName;
  52.         LONG            fileSize;
  53.         
  54.     protected:    
  55.         VOID    cleanUp    (VOID);
  56.     };
  57.  
  58. ManagerWindowC_ListEntry::ManagerWindowC_ListEntry    (GUIC_FileExamineC *file, STRPTR temp, GUIC_TextfieldC *message)
  59. {
  60.     CHAR dummy[1024];
  61.  
  62.     fileName        = 0;
  63.     GUIC_SystemC::reallocString(&fileName, file->getName());
  64.  
  65.     thumbnailName    = 0;
  66.     fileSize                = file->getSize();
  67.     dimensions            = 0;
  68.     
  69.     /* Nachschauen, ob schon ein Thumbnail im TMP Verzeichnis liegt */
  70.     try
  71.         {
  72.         GUIC_FileExamineC filex ( temp, file->getFilePart() );
  73.         GUIC_SystemC::reallocString ( &dimensions, filex.getFilenote() );
  74.         GUIC_SystemC::reallocString ( &thumbnailName, filex.getName() );
  75.         }
  76.     catch (GUIC_Exception &x)
  77.         {
  78.         /* Dann liegt noch kein Thumbnail vor */
  79.         try
  80.             {
  81.             sprintf(dummy, "Creating thumbnail for file: %s", fileName);
  82.             message->setText(dummy);
  83.             
  84.             GUIC_GGFXPictureC pic (fileName);
  85.  
  86.             LONG w = pic.getWidth();
  87.             LONG h = pic.getHeight();
  88.             
  89.             sprintf(dummy, "%ld x %ld", w, h );
  90.             GUIC_SystemC::reallocString(&dimensions, dummy);
  91.             
  92.             pic.scaleToBox(100,100);
  93.             
  94.             strcpy(dummy, temp);
  95.             AddPart(dummy, file->getFilePart(), 1024);
  96.             GUIC_SystemC::reallocString(&thumbnailName, dummy);
  97.             
  98.             pic.saveJPEG(thumbnailName, 90);
  99.             
  100.             GUIC_FileExamineC filex(thumbnailName);
  101.             filex.setFilenote(dimensions);
  102.             }
  103.         catch (GUIC_Exception &x) { GUIC_SystemC::reallocString(&dimensions, "No memory!"); }
  104.         }
  105. }
  106. ManagerWindowC_ListEntry::~ManagerWindowC_ListEntry    (VOID)
  107. {
  108.     if (fileName)    delete [] fileName;
  109. }
  110.  
  111. STRPTR     ManagerWindowC_ListEntry::getClass                (VOID)
  112. {
  113.     return "ManagerWindowC_ListEntry";
  114. }
  115. VOID        ManagerWindowC_ListEntry::cleanUp                    (VOID)
  116. {
  117. }
  118. LONG        ManagerWindowC_ListEntry::compare                (GUIC_ObjectC &o)
  119. {
  120.     return Stricmp(fileName, ((ManagerWindowC_ListEntry *)&o)->fileName); // Just compare the two file names    
  121. }
  122. VOID        ManagerWindowC_ListEntry::print                        (VOID)
  123. {
  124.     cout << "[" << getClass() << "," << this << ",Name=" << fileName << "]" << endl;
  125. }
  126.  
  127. /*********************************************************************************************************/
  128.  
  129. ManagerWindowC::ManagerWindowC             (GUIC_ApplicationC &a, GUIC_ScreenC &s, PrefsWindowC &p) : GUIC_WindowC(20,20)
  130. {
  131.     app                 = &a;
  132.     screen             = &s;
  133.     pWindow            = &p;
  134.     
  135.     pa_window        = new GUIC_PanelC             (GUIC_Vertical);
  136.     sp_line1            = new GUIC_SeparatorC    (GUIC_Horizontal);
  137.     sp_line2            = new GUIC_SeparatorC    (GUIC_Horizontal);
  138.     
  139.     /* 1. Zeile: Quell-Pfad */
  140.     pa_sourcePath    = new GUIC_PanelC                (GUIC_Horizontal);
  141.     la_sourcePath        = new GUIC_LabelC                ("_Source Path:");
  142.     bt_sourcePath    = new GUIC_ImageButtonC    (GUIC_PathImage);
  143.     tf_sourcePath        = new GUIC_TextfieldC            (GUIC_Text);
  144.     
  145.     bt_sourcePath->setShortcut('s');
  146.     
  147.     pa_sourcePath->add(la_sourcePath);
  148.     pa_sourcePath->add(tf_sourcePath);
  149.     pa_sourcePath->add(bt_sourcePath);
  150.  
  151.     /* 2. Zeile: Thumbnails */
  152.     LONG x=1, y=1;
  153.     pa_thumbnails    = new GUIC_PanelC            (5, 3);
  154.     for (LONG i=0; i<NUMBER_OF_THUMBNAILS; i++) 
  155.         {
  156.         bt_thumbnails[i] = new GUIC_SlideButtonC (NULL, 100, 100);
  157.         pa_thumbnails->add(bt_thumbnails[i], x, y);
  158.         x++;
  159.         if (x == 6) { y++; x=1; }
  160.         }
  161.  
  162.     /* 2. Zeile: Ziel-Pfad */
  163.     pa_destPath    = new GUIC_PanelC                (GUIC_Horizontal);
  164.     la_destPath    = new GUIC_LabelC                ("_Destination Path:");
  165.     bt_destPath    = new GUIC_ImageButtonC    (GUIC_PathImage);
  166.     tf_destPath    = new GUIC_TextfieldC            (GUIC_Text);
  167.     
  168.     bt_destPath->setShortcut('d');
  169.     
  170.     pa_destPath->add(la_destPath);
  171.     pa_destPath->add(tf_destPath);
  172.     pa_destPath->add(bt_destPath);
  173.  
  174.     /* 4. Zeile: Message */
  175.     pa_message     = new GUIC_PanelC (GUIC_Horizontal);
  176.     la_message    = new GUIC_LabelC ("Message:");
  177.     tf_message    = new GUIC_TextfieldC (GUIC_Text);
  178.  
  179.     pa_message->add(la_message);
  180.     pa_message->add(tf_message);
  181.     
  182.     pa_window->add(pa_sourcePath);
  183. //    pa_window->add(pa_thumbnails);
  184.     pa_window->add(sp_line1);
  185.     pa_window->add(pa_destPath);
  186.     pa_window->add(sp_line2);
  187.     pa_window->add(pa_message);
  188.     
  189.     prop    = new GUIC_PropWithArrowsC (0, 10, 5);
  190.     pa_window->add(prop);
  191.     
  192.     add(pa_window);
  193.     
  194.     activate();
  195.     setTitle("Gallery - Manager");
  196.     setGuideContext("ManagerWindow");
  197.  
  198.     app->addPrefs("ManagerWindow", this);
  199.     app->addPrefs("ManagerWindowSourcePath", pr_sourcePath);
  200.     app->addPrefs("ManagerWindowDestinationPath", pr_destPath);
  201. }
  202. ManagerWindowC::~ManagerWindowC         (VOID)
  203. {
  204.     cleanUp();
  205. }
  206.  
  207. /*********************************************************************************************************/
  208.  
  209. STRPTR    ManagerWindowC::getClass        (VOID)
  210. {
  211.     return "ManagerWindowC";
  212. }
  213.  
  214. BOOL     ManagerWindowC::action             (GUIC_EventC &event)
  215. {
  216.     static BOOL firstTime = TRUE;
  217.     
  218.     switch (event.id)
  219.         {
  220.         case GUIC_GadgetEvent:
  221.             return TRUE;
  222.             break;
  223.         case GUIC_ObjectEvent:
  224.             if (event.object == (GUIC_GUIObjectC *) bt_sourcePath)
  225.                 {
  226.                 if (pr_sourcePath.request(this)) 
  227.                     {
  228.                     app->setBusy(TRUE);
  229.                     tf_sourcePath->setText ( pr_sourcePath.getPath() );
  230.                     setSource();
  231.                     app->setBusy(FALSE);
  232.                     }
  233.                 }
  234.             else if (event.object == (GUIC_GUIObjectC *) bt_destPath)
  235.                 {
  236.                 if (pr_destPath.request(this)) tf_destPath->setText(pr_destPath.getPath());
  237.                 }
  238.             else if (event.object == (GUIC_GUIObjectC *) prop)
  239.                 {
  240.                 }
  241.             else // Thumbnails abprüfen
  242.                 {
  243.                 for (LONG i=0; i<NUMBER_OF_THUMBNAILS; i++)
  244.                     {
  245.                     if (event.object == (GUIC_GUIObjectC *) bt_thumbnails[i])
  246.                         {
  247.                         LONG thumbnail = firstThumbnail + i;
  248.                         if (thumbnail <= sourceFiles.length())
  249.                             {
  250.                             ManagerWindowC_ListEntry *entry = (ManagerWindowC_ListEntry *) sourceFiles.objectAt(thumbnail);
  251.                             CHAR dummy[1024];
  252.                             sprintf(dummy, "Filename: %s\nFilesize: %ld\nDimensions: %s", entry->fileName, entry->fileSize, entry->dimensions);
  253.                             GUIC_MessageC message ("Picture Information:", dummy, "Show|Delete|Move|Copy|Cancel");
  254.                             LONG answer = message.request(this);
  255.                             switch (answer)
  256.                                 {
  257.                                 case 1:
  258.                                     showFile(entry);
  259.                                     break;
  260.                                 case 2:
  261.                                     deleteFile(entry, i);
  262.                                     break;
  263.                                 case 3:
  264.                                     moveFile(entry, i);
  265.                                     break;
  266.                                 case 4:
  267.                                     copyFile(entry);
  268.                                     break;
  269.                                 }
  270.                             }
  271.                         }
  272.                     }
  273.                 }
  274.             return TRUE;
  275.             break;
  276.         case GUIC_OpenWindow:
  277.             setBusy(TRUE);
  278.             tf_sourcePath->setText(pr_sourcePath.getPath());
  279.             tf_destPath->setText(pr_destPath.getPath());
  280.             if (firstTime) setSource(); 
  281.             firstTime = FALSE;
  282.             setBusy(FALSE);
  283.             return TRUE;
  284.             break;
  285.         case GUIC_CloseWindow:
  286.             screen->remove(this);
  287.             return TRUE;
  288.             break;
  289.         }
  290.     return FALSE;
  291. }
  292.  
  293. VOID        ManagerWindowC::setSource        (VOID)
  294. {
  295.     ManagerWindowC_ListEntry *entry;
  296.     CHAR        dummy[128];
  297.     LONG     count = 1;
  298.     STRPTR     temp = pWindow->ps_temporaryPath->get();
  299.                     
  300.     // Die alte Liste löschen 
  301.     while (sourceFiles.length()) delete (ManagerWindowC_ListEntry *) sourceFiles.remove(1);
  302.     
  303.     // Und die neuen Files einlesen
  304.     try
  305.         {
  306.         GUIC_FileExamineC *filex;
  307.         GUIC_DirectoryExamineC direx (pr_sourcePath.getPath());
  308.         
  309.         while (( filex = direx.examineNext() ) )
  310.             {
  311.             if (filex->getFileType() == GUIC_PictureFile)
  312.                 {
  313.                 sprintf(dummy, "Scanning source directory: %ld", count++);
  314.                 tf_message->setText(dummy);
  315.                 entry = new ManagerWindowC_ListEntry(filex, temp, tf_message);
  316.                 if (entry) sourceFiles.addSorted(entry); // sonst war kein Speicher mehr frei zum Laden des Files
  317.                 }
  318.             }
  319.         }
  320.     catch (GUIC_Exception &x)
  321.         {
  322.         GUIC_ErrorC err ("Exception caught:", x.getMessage());
  323.         err.request(this);
  324.         }
  325.         
  326.     tf_message->setText("Loading thumbnails.");
  327.     
  328.     LONG len = sourceFiles.length(), i;
  329.     
  330.     for (i=0; i<NUMBER_OF_THUMBNAILS; i++)
  331.         {
  332.         if (i < len)
  333.             {
  334.             entry = (ManagerWindowC_ListEntry *) sourceFiles.objectAt(i+1);
  335.             bt_thumbnails[i]->set(entry->fileName);
  336.             }
  337.         else bt_thumbnails[i]->set(NULL);
  338.         }
  339.  
  340.     firstThumbnail=1;
  341.     tf_message->setText("");
  342. }
  343. VOID        ManagerWindowC::showFile        (ManagerWindowC_ListEntry *entry)
  344. {
  345. }
  346. VOID        ManagerWindowC::deleteFile        (ManagerWindowC_ListEntry *entry, LONG button)
  347. {
  348.     GUIC_FileC f1 ( entry->fileName );
  349.     GUIC_FileC f2 ( entry->thumbnailName ); 
  350.     
  351.     if (f1.remove()) 
  352.         {
  353.         bt_thumbnails[button]->set(NULL);
  354.         GUIC_SystemC::reallocString(&entry->fileName, "");
  355.         }
  356.     else 
  357.         {
  358.         GUIC_ErrorC err ("Caution:", "Could not delete file from disk.");
  359.         err.request(this);
  360.         }
  361.                 
  362.     if (! f2.remove())
  363.         {
  364.         GUIC_ErrorC err ("Caution:", "Could not delete thumbnail from disk.");
  365.         err.request(this);
  366.         }
  367. }
  368. VOID        ManagerWindowC::moveFile        (ManagerWindowC_ListEntry *entry, LONG button)
  369. {
  370.     if (copyFile(entry)) deleteFile(entry, button);
  371. }
  372. BOOL        ManagerWindowC::copyFile            (ManagerWindowC_ListEntry *entry)
  373. {
  374.     GUIC_FileC f1    ( entry->fileName );
  375.     
  376.     STRPTR     path    = pr_destPath.getPath();
  377.     STRPTR     file        = f1.getFilePart();
  378.     LONG     len        = strlen (path) + strlen(file) + 5;
  379.     STRPTR     buffer    = new CHAR [len];
  380.     
  381.     strcpy(buffer, path);
  382.     AddPart(buffer, file, len);
  383.     
  384.     if (f1.doesExist())
  385.         {
  386.         GUIC_FileC *dest = new GUIC_FileC (buffer);
  387.         BOOL exists=dest->doesExist();
  388.         delete dest; dest=0;
  389.         
  390.         if (exists)
  391.             {
  392.             STRING s="File\n'";
  393.             s += buffer;
  394.             s += "'\nexists already";
  395.             GUIC_MessageC msg ("Caution:", s, "Override|More information|Cancel");
  396.             LONG result = msg.request(this);
  397.             if (result == 0) return FALSE;
  398.             if (result == 2) 
  399.                 {
  400. /*                sleep();
  401.                 pWindow->showPicture("");
  402.                 if (iWindow == 0) iWindow = new InformationWindowC(*app, *screen);
  403.                 screen->add(iWindow);
  404.                 iWindow->setPictures(f1.getName(), buffer1);
  405.                 waken(); 
  406. */                
  407.                 cerr << "Noch nicht implementiert." << endl;
  408.                 return FALSE;
  409.                 }
  410.             }
  411.             
  412.         if (f1.copy ( buffer ) ) return TRUE;
  413.         
  414.         GUIC_ErrorC err ("Caution:", "Could not copy picture to destination.");
  415.         err.request(this);
  416.         }
  417.         
  418.     return FALSE;
  419.  
  420. }
  421.  
  422. /*********************************************************************************************************/
  423.  
  424. VOID         ManagerWindowC::cleanUp            (VOID)
  425. {
  426.     while (sourceFiles.length()) delete (ManagerWindowC_ListEntry *) sourceFiles.remove(1);
  427.     
  428.     delete pa_message;
  429.     delete la_message;
  430.     delete tf_message;
  431.  
  432.     for (LONG i=0; i<NUMBER_OF_THUMBNAILS; i++) delete bt_thumbnails[i];
  433.     delete pa_thumbnails;
  434.  
  435.     delete bt_destPath;
  436.     delete la_destPath;
  437.     delete tf_destPath;
  438.     delete pa_destPath;
  439.  
  440.     delete bt_sourcePath;
  441.     delete la_sourcePath;
  442.     delete tf_sourcePath;
  443.     delete pa_sourcePath;
  444.     
  445.     delete sp_line1;
  446.     delete sp_line2;
  447.     delete pa_window;
  448.     
  449.     delete prop;
  450. }
  451.  
  452.